<!-- 使用 computed 计算把单页的数组，变成了双页的 -->
<template>
	<div class='icons'>
		<swiper :options="swiperOption">
			<swiper-slide v-for="(page,index) of pages" :key="index">
				<div class="icon" v-for="item of page" :key="item.id">
					<div class="icon-img">
						<img class="icon-img-content" :src="item.imgUrl"></img>
					</div>
					<p class="icon-desc">{{item.desc}}</p>
				</div>
			</swiper-slide>
			<!-- <swiper-slide>
				<div class="icon">
					<div class="icon-img">
						<img class="icon-img-content" src="https://imgs.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png"></img>
					</div>
					<p class="icon-desc">景点门票</p>
				</div>
			</swiper-slide> -->
		</swiper>
	</div>

</template>

<script>
	export default {
		name: 'HomeIcons',
		props: {
			list: Array
		},
		data () {
			return {
				swiperOption: {
					autoplay:false
				}
			}
		},
		// 使用 computed 计算解决 第九个图标被隐藏的问题
		computed:{
			pages () {
				const pages = []
				this.list.forEach((item,index) => {
					const page = Math.floor(index/8);
					if (!pages[page]) {
						pages[page] = [];
					}
					pages[page].push(item);
				})
				return pages;
			}
		}
	}
</script>

<style>
	.icons {
		margin-top: .1rem;
		overflow: hidden;
		height: 0;
		padding-bottom: 50%;
		/* background: green; */
	}
	
	.icons >>> .swiper-container {
		height: 0;
		padding-bottom: 50%;
	}
 
	.icon {
		position: relative;
		overflow: hidden;
		float: left;
		height: 0;
		width: 25%;
		padding-bottom: 25%;
		/* background: red; */
	}

	.icon-img {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: .44rem;
		/* background: blue; */
		padding: .1rem;
		box-sizing: border-box;
	}

	.icon-desc {
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		height: .44rem;
		/* 		line-height: .44rem; */
		color: #333;
		text-align: center;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.icon-img-content {
		display: block;
		/* 快速居中效果 */
		margin: 0 auto;
		height: 100%;
	}
</style>
